<?php

namespace addons\Merchants\console\controllers;

use Yii;
use yii\console\Controller;

/**
 * 定时结算
 *
 * 命令行
 *
 * '''
 *      php ./yii merchants/settle-account/index
 * '''
 * Class SettleAccountController
 * @package addons\Merchants\console\controllers
 * @author YiiFrame <21931118@qq.com>
 */
class SettleAccountController extends Controller
{
    public function actionIndex()
    {
        // 事务
        $transaction = Yii::$app->db->beginTransaction();
        try {
            Yii::$app->services->merchantSettleAccount->settleAccounts();

            $transaction->commit();
        } catch (\Exception $e) {
            $transaction->rollBack();

            Yii::error($e->getMessage());
        }
    }
}